#define _CRT_SECURE_NO_WARNINGS	1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

 /**
  * Definition for singly-linked list.
  * struct ListNode {
  *     int val;
  *     struct ListNode *next;
  * };
  */


struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode* cut = head, * pevr = NULL;
    while (cut)
    {
        if (cut->val == val)
        {
            if (cut == head)
            {
                head = cut->next;
                cut = head;
            }
            else
            {
                pevr->next = cut->next;
                cut = pevr->next;
            }
        }
        else
        {
            pevr = cut;
            cut = cut->next;
        }
    }
    return head;
}
